package com.sh.suhe.utildemos.utils;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.sh.suhe.utildemos.SDKManager;


public class ToastUtils {

    private static boolean ignoreNetworkError = false;


    public static void showToast(final String text) {
        final Context context = SDKManager.getInstance().getContext();
        if (context == null) {
            return;
        }
        if (ThreadUtils.isMainThread()) {
            showToastOnUi(context, text);
        } else {
            ThreadUtils.runOnUiThread(new Runnable() {
                public void run() {
                    showToastOnUi(context, text);
                }
            });
        }
    }

    public static void showToast(final int strId) {
        final Context context = SDKManager.getInstance().getContext();
        if (context == null) {
            return;
        }
        showToast(context.getString(strId));
    }

    private static void showToastOnUi(final Context context, final String text) {
        if (!TextUtils.isEmpty(text)) {
            Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
//            int height = DeviceUtil.getScreenHeight(context);
//            toast.setGravity(Gravity.BOTTOM, 0, height / 7);
//            LinearLayout toastView = (LinearLayout) toast.getView();
//            toastView.setBackgroundResource(R.drawable.bg_toast);
//            TextView textView = (TextView) toastView.getChildAt(0);
//            textView.setPadding(20, 0, 20, 0);
//            textView.setTextColor(Color.parseColor("#ffffff"));
//            textView.setText(text);
            toast.show();
        }
    }
}
